package com.md.controller;

import com.md.entity.Blog;
import com.md.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/blog")
public class Controllers {
    @Autowired
    private BlogService blogService;
    @GetMapping
    public List<Blog> selectAll() {
        return blogService.selectAll();
    }

    @GetMapping("{id}")
    public Blog selectById(@PathVariable String id) {
        return blogService.selectById( Integer.parseInt(id));

    }
    @GetMapping(params = "name")
    public List<Blog> selectName(String name) {
        return blogService.selectName(name);
    }
    @DeleteMapping("{id}")
    public int deleteById(@PathVariable String id) {
        return blogService.deleteById(Integer.parseInt(id));
    }
    @PostMapping
    public int insertById(@RequestBody Blog blog) {
        return blogService.insertById(blog);
    }
    @PutMapping
    public int updateById(@RequestBody Blog blog) {
        return blogService.updateById(blog);
    }

}
